package com.ruoyi.dataserver.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.util.TypeUtils;
import com.ruoyi.dataserver.model.MAPTABLE;
import com.ruoyi.dataserver.service.ISearchTableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;


/**
 * @ProjectName
 * @Package com.lab.dataserver.service.impl
 * @ClassName TopologyAnalyzeServceImpl
 * @Description 超图查询表名逻辑层
 * @Company lab
 * @Author wangzhx
 * @Date 2022/3/2  11:55
 * @UpdateUser
 * @UpdateDate
 * @UpdateRemark
 * @Version 1.0.0
 */
@Slf4j
@Component
public class SearchTableServceImpl implements ISearchTableService {

    @Autowired
    public JdbcTemplate jdbcTemplate;


    @Override
    public String searchLineTable(String dm) {
        String sql = "select smtablename from smregister where smdatasetname = '"+dm+"_LINE' ";
        Object obj = new Object();
        obj = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<MAPTABLE>(MAPTABLE.class));
        TypeUtils.compatibleWithJavaBean = true;    // JSON转换设置：不转换大小写
        JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(obj));
        String tableName = jsonObject.get("SMTABLENAME").toString();
        return tableName;
    }
    @Override
    public String searchPointTable(String dm) {
        String sql = "select smtablename from smregister where smdatasetname = '"+dm+"_POINT' ";
        Object obj = new Object();
        obj = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<MAPTABLE>(MAPTABLE.class));
        TypeUtils.compatibleWithJavaBean = true;    // JSON转换设置：不转换大小写
        JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(obj));
        String tableName = jsonObject.get("SMTABLENAME").toString();
        return tableName;
    }
}
